<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="scripts/jquery/jquery-1.7.1.js"></script>
<link href="style/authority/basic_layout.css" rel="stylesheet" type="text/css">
<link href="style/authority/common_style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="scripts/authority/commonAll.js"></script>
<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript" src="scripts/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css" href="style/authority/jquery.fancybox-1.3.4.css" media="screen"></link>
<script type="text/javascript" src="scripts/artDialog/artDialog.js?skin=default"></script>
    
    <title>My JSP 'Newgoods.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type="text/javascript">

		
		function isnumber(num)
		{
			if(num>'9'||num<'0') return false;
			return true;
		}	
		function changecategory()
		{
			var name1=document.getElementById("category1").value;
			document.form1.action="servlet/Newgoodsservlet?type=newgoods&name1="+name1+"&name2=all";
			document.form1.submit();
			document.form1.action="servlet/Newgoodsservlet?type=insert";
		}
		function checkname()
		{
			if(document.getElementById("product_name").value=="") {document.getElementById("namelabel").innerHTML="<font color='red'>商品名不能为空</font>"; return false;}
			else {document.getElementById("namelabel").innerHTML=""; return true;};
		}
		function checkunit()
		{
			if(document.getElementById("product_unit").value=="") {document.getElementById("unitlabel").innerHTML="<font color='red'>单位不能为空</font>"; return false;}
			else {document.getElementById("unitlabel").innerHTML=""; return true;}
		}
		
		function checkcategory1()
		{
			if(document.getElementById("category1").value=="all") {document.getElementById("category1label").innerHTML="<font color='red'>请选择一级分类</font>"; return false;}
			else {document.getElementById("category1label").innerHTML=""; return true;}
		}
		
		function checkprice()
		{
			var st=document.getElementById("product_price").value;
			if(st=="") {document.getElementById("pricelabel").innerHTML="<font color='red'>原价不能为空</font>"; return false;}
			else 
			{
				var reg = new RegExp("^[0-9][0-9]*\.?[0-9]*$");
				var ans=true;
				ans = reg.test(st);
				//alert(reg.test(st));
				if(ans)	{document.getElementById("pricelabel").innerHTML=""; return true;}
				else {document.getElementById("pricelabel").innerHTML="<font color='red'>非法输入</font>"; return false;}
				
			}
			 
		}
		function checkprime_cost()
		{
			var st=document.getElementById("product_prime_cost").value;
			if(st=="") {document.getElementById("prime_costlabel").innerHTML="<font color='red'>成本不能为空</font>"; return false;}
			else 
			{
				var reg = new RegExp("^[0-9][0-9]*\.?[0-9]*$");
				var ans=true;
				ans = reg.test(st);
				//alert(reg.test(st));
				if(ans)	{document.getElementById("prime_costlabel").innerHTML="";return true;}
				else {document.getElementById("prime_costlabel").innerHTML="<font color='red'>非法输入</font>"; return false;}
				
			}
			 
		}
		function checkdiscount(){
			var st = document.getElementById("product_discount").value;
			if(st=="") {document.getElementById("discountlabel").innerHTML="<font color='red'>折扣不能为空</font>"; return false;}
			else{
				var reg = new RegExp("^(0?(\.[0-9]*)+)|1$");
				var ans=true;
				ans = reg.test(st);
				if(st=="1") ans=true;
				
				//alert(reg.test(st));
				if(ans)	{document.getElementById("discountlabel").innerHTML="";return true;}
				else {document.getElementById("discountlabel").innerHTML="<font color='red'>需要不大于1的小数</font>"; return false;}
			}
		}
		function checkproduct_type(){
			var st = document.getElementById("product_type").value;
			if(st==""){document.getElementById("product_typelabel").innerHTML="<font color='red'>型号不能为空</font>"; return false;}
			else{
				document.getElementById("product_typelabel").innerHTML="";
				return true;
			}
		}
		function checkproduct_producer(){
			var st = document.getElementById("product_producer").value;
			if(st==""){document.getElementById("producerlabel").innerHTML="<font color='red'>厂商不能为空</font>"; return false;}
			else{
				document.getElementById("producerlabel").innerHTML="";
				return true;
			}
		}
		function checkwarning_number(){
			var st = document.getElementById("product_warning").value;
			if(st=="") {document.getElementById("warninglabel").innerHTML="<font color='red'>警戒值不能为空</font>"; return false;}
			else{
				var reg = new RegExp("[1-9][0-9]*$");
				var ans=true;
				ans = reg.test(st);
				//alert(reg.test(st));
				if(ans)	{document.getElementById("warninglabel").innerHTML="";return true;}
				else {document.getElementById("warninglabel").innerHTML="<font color='red'>需要数字</font>"; return false;}
			}
		}
		function checkmax_number(){
			var st = document.getElementById("product_max").value;
			if(st=="") {document.getElementById("maxlabel").innerHTML="<font color='red'>最大值不能为空</font>"; return false;}
			else{
				var reg = new RegExp("^[1-9][0-9]*$");
				var ans=true;
				ans = reg.test(st);
				//alert(reg.test(st));
				if(ans)	{document.getElementById("maxlabel").innerHTML="";return true;}
				else {document.getElementById("maxlabel").innerHTML="<font color='red'>需要数字</font>"; return false;}
			}
		}
		function checkqg(){
			var st = document.getElementById("product_qg_period").value;
			if(st==""){document.getElementById("qglabel").innerHTML="<font color='red'>保质期不能为空</font>"; return false;}
			else{
				document.getElementById("qglabel").innerHTML="";
				return true;
			}
		}
		function checkall()
		{
			if(!checkname()) return;
			if(!checkunit()) return;
			if(!checkcategory1()) return;
			if(!checkprice()) return;
			if(!checkprime_cost()) return;
			if(!checkdiscount()) return;
			if(!checkproduct_type()) return;
			if(!checkproduct_producer()) return;
			if(!checkwarning_number()) return;
			if(!checkmax_number()) return;
			if(!checkqg()) return;
			var max = document.getElementById("product_max").value;
			var warning = document.getElementById("product_warning").value;
			if(parseInt(max)<parseInt(warning)) return;
			document.form1.action="servlet/Newgoodsservlet?type=insert";
			document.form1.submit();
		}
	</script>
	

  </head>
  
  <body>
	<div id="container">	
		<div class="ui_content">
			<div class="ui_tb">
				<form name="form1" method="post">    	
			    	<table class="table" width="100%" align="center">
			    		<tr>
			    			<th width="15%">商品名</th>
			    			<td width="35%"><input class="ui_input_txt02" id="product_name" value="${updateproduct==null?'':updateproduct.product_name}" name="product_name" onblur="checkname()" type="text"/><label id="namelabel"></label></td>
			    			<th width="15%">单位</th>   
							<td width="35%"><input class="ui_input_txt02" id="product_unit" value="${updateproduct==null?'':updateproduct.unit}" name="product_unit" onblur="checkunit()" type="text"/><label id="unitlabel"></label></td>			
			    		</tr>
			    		<tr>
			    			<th>一级分类</th>
			    			<td>
			    				<select onblur="checkcategory1()" class="ui_select01" name="name1" id="category1" onChange="changecategory()">
			    					<option value="all" selected="selected"></option>
				              		<c:forEach items="${category1}" var="temp">
				              			<c:if test="${temp==selectoption1}"><option value="${temp}" selected="selected">${temp} </option></c:if>
				              			<c:if test="${temp!=selectoption1}"><option value="${temp}">${temp} </option></c:if>	              			
				              		</c:forEach>
			    				</select>
			    				<label id="category1label"></label>
			    			</td>
			    			<th>二级分类</th>
			    			<td>
			    				<select class="ui_select01" name="name2" id="category2">
				              		<c:forEach items="${category2}" var="temp">
				              			<c:if test="${temp==selectoption2}"><option value="${temp}" selected="selected">${temp} </option></c:if>
				              			<c:if test="${temp!=selectoption2}"><option value="${temp}">${temp} </option></c:if>	              			
				              		</c:forEach>    				
			    				</select>
			    			</td>
			    		</tr>
			    		    <tr>
			    			<th>原价</th>
			    			<td><input class="ui_input_txt02" onblur="checkprice()" name="product_price" id="product_price" value="${updateproduct==null?'':updateproduct.price}" type="text"/><label id="pricelabel"></label></td>
			    			<th>成本</th>   
							<td><input class="ui_input_txt02" name="product_prime_cost" id="product_prime_cost" value="${updateproduct==null?'':updateproduct.prime_cost}" type="text" onblur="checkprime_cost()" /><label id="prime_costlabel"></label></td>			
			    		</tr>
			    		<tr>
			    			<th>折扣</th>
			    			<td><input class="ui_input_txt02" name="product_discount" id="product_discount" value="${updateproduct==null?'':updateproduct.discount}" type="text" onblur="checkdiscount()"/><label id="discountlabel"></label></td>
			    			<th>型号</th>   
							<td><input class="ui_input_txt02" name="product_type" id="product_type" value="${updateproduct==null?'':updateproduct.type}" type="text" onblur="checkproduct_type()"/><label id="product_typelabel"></label></td>			
			    		</tr>
			    		<tr>
			    			<th>供应商</th>
			    			<td>
			    				<select class="ui_select01" name="product_supplier" id="supplier">
				              		<c:forEach items="${supplier}" var="temp">
				              			<c:if test="${temp==selectoption3}"><option value="${temp}" selected="selected">${temp}</option></c:if>
				              			<c:if test="${temp!=selectoption3}"><option value="${temp}">${temp}</option></c:if>	             			
				              		</c:forEach>    				
			    				</select>
			    			</td>
			    			<th>厂商</th>   
							<td><input class="ui_input_txt02" name="product_producer" id="product_producer" value="${updateproduct==null?'':updateproduct.producer}" type="text" onblur="checkproduct_producer()"/><label id="producerlabel"></label></td>			
			    		</tr>    	
			    		<tr>
			    			<th>预警值</th>
			    			<td><input class="ui_input_txt02" name="product_warning" id="product_warning" value="${updateproduct==null?'':updateproduct.warning_number}" type="text" onblur="checkwarning_number()"/><label id="warninglabel"></label></td>
			    			<th>最大值</th>   
							<td><input class="ui_input_txt02" name="product_max" id="product_max" value="${updateproduct==null?'':updateproduct.max_number}" type="text" onblur="checkmax_number()"/><label id="maxlabel"></label></td>			
			    		</tr>	
			    		<tr>
			    			<th>能否退货</th>
			    			<td>
			    				<input name="can_return" value="1" type="radio" checked="checked"/>能 
			    				<input name="can_return" value="0" type="radio"/>不能
			    			</td>
			    			<th>保质期</th>   
							<td><input class="ui_input_txt02" name="product_qg_period" id="product_qg_period" value="${updateproduct==null?'':updateproduct.qg_period}" type="text" onblur="checkqg()"/><label id="qglabel"></label></td>			
			    		</tr>
			    		<tr>
			    			<th>备注</th>
			    			<td colspan="3"><input class="ui_input_txt03" name="product_tips" size="64%" value="${updateproduct==null?'':updateproduct.tips}" type="text"></td>
			    		</tr>  
			    		<tr>
			    			<td colspan="2" align="center"><input class="ui_input_btn01" value="重置" type="reset"/></td>			    			
			    			<td colspan="2" align="center"><input class="ui_input_btn01" value="提交" type="button" onclick="checkall()"/></td>
			    		</tr>  	
			    	</table>
			    	<input name="delete_id" value="${updateproduct==null?'new':updateproduct.product_id}" type="hidden">
			    </form>
			</div>
		</div>
	</div>    
  </body>
</html>
